﻿@using Library
@model Ecommerce.Models.EditPageViewModel

@{
    ViewBag.Title = NOWCulture.GetString("Create new") + "/" + NOWCulture.GetString("Edit") + " " + NOWCulture.GetString("page");
    Layout = "_Layout.cshtml";

    var selectedList = ViewBag.SelectedList as List<SelectListItem>;
}
<h2 class="pull-left">@ViewBag.Title</h2>
<div class="pull-right langarea">
    @foreach (var dic in NOWCulture.Dictionary)
    {
        var langName = NOWCulture.GetString(dic.Key.Name);
        if (dic.Key.Id == Model.Culture)
        {
            <a class="btn btn-primary btn-xs" href="@Url.Action("EditPage", new { @id = Model.Id, @selectedCulture = dic.Key.Id })"><img src="~/Content/cultures/@dic.Key.Id/icon.png" alt="@langName" width="16" height="16" /> @langName</a>
        }
        else
        {
            <a class="btn btn-default btn-xs" href="@Url.Action("EditPage", new { @id = Model.Id, @selectedCulture = dic.Key.Id })"><img src="~/Content/cultures/@dic.Key.Id/icon.png" alt="@langName" width="16" height="16" /> @langName</a>
        }
    }
</div>
<div class="clearfix"></div>
@using (Html.BeginForm("EditPage", "Admin", FormMethod.Post, new { @id = "page-form", @class = "form-horizontal", @data_modelid = (ViewBag.IsEdit ? Model.Id.ToString() : "-1") }))
{
    @Html.AntiForgeryToken()
    if (ViewBag.IsEdit)
    {
        @Html.HiddenFor(m => m.Id)
    }
    @Html.HiddenFor(m => m.Culture)
    <div class="form-group">
        @Html.EditorFor(m => m.Content, "Html")
    </div>
    if (selectedList != null && selectedList.Count > 0)
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">@NOWCulture.GetString("Page group")</label>
            <div class="col-sm-10">
                @Html.DropDownListFor(m => m.PageGroupId, selectedList, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.PageGroupId, "", new { @class = "text-danger" })
            </div>
        </div>
    }
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Webpage title")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.WebTitle, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => m.WebTitle, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Keywords")</label>
        <div class="col-sm-10">
            @Html.TextAreaFor(m => m.Keywords, new { @class = "form-control", @maxlength = 150, @rows = 3 })
            @Html.ValidationMessageFor(m => m.Keywords, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Webpage description")</label>
        <div class="col-sm-10">
            @Html.TextAreaFor(m => m.WebDescription, new { @class = "form-control", @maxlength = 200, @rows = 3 })
            @Html.ValidationMessageFor(m => m.WebDescription, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">@NOWCulture.GetString("Url")</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(m => m.Url, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => m.Url, "", new { @class = "text-danger" })
        </div>
    </div>
    @Html.ValidationSummary(true, "", new { @class = "bg-danger" })
    <div class="form-group">
        <div class="pull-left">
            <a class="btn btn-warning" href="@Url.Action("Pages")" title="@NOWCulture.GetString("Go back")"><span class="glyphicon glyphicon-arrow-left"></span> @NOWCulture.GetString("Go back")</a>
        </div>
        <div class="pull-right">
            <input type="reset" class="btn btn-default" value="@NOWCulture.GetString("Reset")">
            <input type="submit" class="btn btn-primary" value="@NOWCulture.GetString("Save")">
        </div>
        <div class="clearfix"></div>
    </div>
}
@section scripts
{
    <script>
    document.currentCulture = '@NOWCulture.CurrentCulture';
    document.twoLetterISOLanguageName = '@NOWCulture.CurrentCultureInfo.TwoLetterISOLanguageName';
    document.contentCssLink = '@Styles.Url("~/Content/css")';
    document.simpleImageBrowserURL = '@(Model.Id > 0 ? Url.Action("ImageBrowser", "Shared", new { @imageDirectoryUrl = "/Content/images/pages/" + Model.Id }) : "")';
    document.simpleImageBrowserUploadActionURL = '@(Model.Id > 0 ? Url.Action("UploadImages", "Shared", new { @imageDirectoryUrl = "/Content/images/pages/" + Model.Id }) : "")';
    </script>
    @(HttpContext.Current.IsDebuggingEnabled ? Scripts.Render("~/bundles/admin-edit-page") : Scripts.RenderFormat(@"<script src=""{0}"" async defer></script>", "~/bundles/admin-edit-page"))
    <script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
}
